/*var http = require("http");
var port = 80;
var ip = '127.0.0.1';
http.createServer(function(request,response){
	response.statusCode = 200;
	response.statusMessage = "perfect!";
	response.server = "private server";
	
	response.write('.'+request.url);
	response.end();
}).listen(port)

console.log('server running at http://%s:%s/',ip,port);*/

var http = require('http');
var ip = "127.0.0.1";
var port = 80;
http.createServer(function (request, response) {
	response.statusCode=200;
	response.statusMessage = "perfect!";
	response.server = "private server";
	var ext = request.url.substr(request.url.lastIndexOf('.')+1);
	var extObj = {
		'html':'text/html',
		'css':'text/css',
		'js':'text/js',
		'jpg':'image/jpeg',
		'png':'image/png',
		'gif':'image/gif',
		'ico':'image/x-icon'
	}
	response.setHeader('Content-Type',extObj[ext]);
	if (extObj[ext]==null) {
		response.setHeader('Content-Type','text/plain');
	}
	var fs = require("fs");
	try{
		var data = fs.readFileSync('.'+request.url);
		response.write(data);
	}catch(e){

	}
	response.end();
}).listen(port);

// 终端打印如下信息
console.log('Server running at http://%s:%s/',ip,port);